class EntryBibListController {
    constructor($rootScope, $scope, $cookieStore, $timeout, $state, EntryService, ngDialog, dialogService, iRunner){

    	var vm = this;

    	vm.$rootScope    = $rootScope;
    	vm.$cookieStore  = $cookieStore;
    	vm.$timeout 	 = $timeout;
    	vm.$state   	 = $state;
    	vm.ngDialog 	 = ngDialog;
    	vm.dialogService = dialogService;
    	vm.iRunner 	     = iRunner;
        vm.EntryService = EntryService;

        vm.deleteAll = function() {
            

            vm.EntryService.postRegisterClearLists(vm.$cookieStore.get('access_token'), vm.$state.params.race_id)
            .then(function(data) {
                // 成功调用
                if (data.code==0) {

                    vm.dialogService.success("选手号已清空");

                } else{
                    console.log("调用失败");
                }
                // 登录信息已过期, 请重新登录
                data.code==-1001&&vm.dialogService.error(data.message, true);
            }, function(data) {
                console.log('error')
            });



        }


        vm.tableSettings = {
            KEYCODE: {
                ENTER: 13,
                DELETE: 46,
                BACKSPACE: 8,
                UP: 38,
                DOWN: 40
            },
            imageTypes: "*.gif;*.jpg;*.jpeg;*.png;",
            dataTable: {

                /*基本参数设置，以下参数设置和默认效果一致*/
                "paginate": true, //翻页功能
                "lengthChange": true, //改变每页显示数据数量
                "filter": true, //过滤功能
                "sort": true, //排序功能
                "info": true,//页脚信息
                "autoWidth": true,//自动宽度
                /*默认排序设置*/
                // "aSorting": [[ 4, "desc" ]],//设置第5个元素为默认排序
                /*默认翻页样式设置*/
                "paginationType": "full_numbers",
                /*是否开启主题*/
                // "jQueryUI": true,
                /*语言设置*/
                "language": {
                    "lengthMenu": "每页显示 _MENU_条",
                    "zeroRecords": "没有找到符合条件的数据",
                    "processing": "加载中...",
                    "info": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
                    "infoEmpty": "没有记录",
                    // "infoFiltered": "(从 _MAX_ 条记录中过滤)",
                    "infoFiltered": "",
                    "search": "搜索：",
                    "paginate": {
                        "first": "首页",
                        "previous": "前一页",
                        "next": "后一页",
                        "last": "尾页"
                    }
                },

                // --- Data
                processing: true,
                serverSide: true,
                // --- Language
                // language: $.extend({}, iRunner.l("DATATABLE"), {
                //     processing: 'Loading...'
                // }),
                // --- Pagination
                pageLength: 50,
                pagingType: "full_numbers",
                lengthMenu: [10, 20, 50, 100, 200],
                // dom: "rt<'page-list-footer'lp>"
                dom: '<"page-list-footer"<br/>lp<"clear">irt<"page-list-footer"lp<"clear">ir'
            }
        }

        //加载表格数据
        var tableData = angular.element('#bib_lists_table').DataTable($.extend({}, vm.tableSettings.dataTable, {
            // --- Data (/registerpicknum/lists?race_id=)
            ajax: iRunner.config.baseUrl + '/registerpicknum/lists?race_id=' + vm.$state.params.race_id + '&access-token=' + this.$cookieStore.get('access_token'),
            order: [0, "desc"], // ID 倒序
            // --- Column       
            columns: iRunner.bibColumns,
            // --- CreatedRow
            createdRow: ( row, data, index ) => {},
            // --- Callback
            initComplete: () => {}
        }));

            // 上下每页条数下拉框同步
            $('.dataTables_length').find('select').on('change', function(event) {
                //清空当前页面数据
                vm.realtimeData = [];
                const select =  $('.dataTables_length').find('select');
                select.val($(this).val())
            });

    }

    
}

EntryBibListController.$inject = ['$rootScope', '$scope', '$cookieStore', '$timeout', '$state', 'EntryService', 'ngDialog', 'dialogService', 'iRunner']; 

export default EntryBibListController;